<?php

	//*****************************************************************************************************************************

	function validaLoginExterno($user, $passwd){
                session_start();
				include_once('config/class.pdo.php');
				include('config/funcoes.php');

                $pdo = new DB();
                $pdo->conexao();
	
				$sql = 'SELECT * FROM  usuario where LOGIN="'.$user.'" AND STATUS <> 0 and ACESSO = "E";';                
                $registro = $pdo->oneReg($sql);
                if(empty($registro))
                {
                        Logger('Login - Falha de login',$user);
                        return false;

                }else{
                        if($registro['LOGIN'] == $user){
							 if($registro['SENHA'] == md5($passwd)){
												$_SESSION["carteirinha"]["id"] = $registro["CODIGO"];
												$_SESSION["carteirinha"]["user"] = $registro["LOGIN"];
												$_SESSION["carteirinha"]["permissao"] = $registro["PERMISSAO"];
												$_SESSION["carteirinha"]["acesso"] = $registro["ACESSO"];

												/* $sql ="SELECT fk_idsetores, fk_idsecretarias FROM usuario_setores WHERE fk_idusuarios='".$registro["idusuarios"]."';";
												$vetor = $pdo->select($sql);
												$_SESSION["frequencia"]["vetor"] = array();
																//array_push($_SESSION["frequencia"]["vetor"],$vetor);
												$_SESSION["frequencia"]["vetor"] = $vetor;

												$_SESSION["frequencia"]["mes"] = mesFrequencia();
												$_SESSION["frequencia"]["ano"] = anoFrequencia(); */
												Logger('Login - Sucesso ',$user);
												return true;

	                        }else{
								Logger('Login - Falha de login ',$user);
								return false;
                	        }
		
                        }else{
							Logger('Login - Falha de login ',$user);
							return false;
                        }
                }
		$pdo = null;
        }

/* 	if(validaAD($_POST['userLogin'], $_POST['userPassword'],'CARTEIRINHA')){
		if(validaLogin($_POST['userLogin'])){
			echo "true";
		}else{
			echo "false";
		}
	}else{ */
		if(validaLoginExterno($_POST['userLogin'], $_POST['userPassword'])){
                        echo "true";
						$_SESSION["lawoffice"]["user"] = $_POST['userLogin'];
						$_SESSION["lawoffice"]["ultimoAcesso"] = time();	
						Logger('Login - Sucesso ',$_POST['userLogin']);	
                }else{
                        echo "false";
						Logger('Login - Falha de login ',$_POST['userLogin']);
                }
	//}
?>
